package com.chencs.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

/**
 * Created by fangzehua on 2017/7/11.
 */
public class StringUtils {

    public static double getCoupon(String x) {
        double price = 0.0d;
        try {
            if (x.indexOf("无条件") > -1) {
                price = Double.parseDouble(x.replace("元无条件券", ""));
            } else {
                price = Double.parseDouble(x.split("减")[1].replace("减", "").replace("元", ""));
            }
        } catch (Exception e) {
            price = 0.0;
        }

        return price;
    }

    public static String repcUrl(String url,String e) throws Exception{
        if(url.indexOf("activityId")!=-1){
            Map<String, String> mapRequest = CRequest.URLRequest(url);
            String newUlr;
            if(!com.alibaba.druid.util.StringUtils.isEmpty(e)){
                 newUlr = "https://uland.taobao.com/coupon/edetail?e="+e+"&activityId="+mapRequest.get("activityid")+"&&pid=mm_16510629_18916799_68766966&itemId="+mapRequest.get("itemid");
            }else{
                 newUlr = "https://uland.taobao.com/coupon/edetail?activityId="+mapRequest.get("activityid")+"&&pid=mm_16510629_18916799_68766966&itemId="+mapRequest.get("itemid");

            }


//            System.out.println("-------------正常--------"+mapRequest.toString()+url);
            return newUlr;
        }else{
//            System.out.println("隐藏"+url+"&mm_16510629_18916799_68766966");

            return "-1";
        }
    }

    public static String repcUrl(String url) throws  Exception{
        if(url.indexOf("activityId")!=-1){
            Map<String, String> mapRequest = CRequest.URLRequest(url);
            String newUlr = "https://uland.taobao.com/coupon/edetail?activityId="+mapRequest.get("activityid")+"&&pid=mm_16510629_18916799_68766966&itemId="+mapRequest.get("itemid");
//            System.out.println("-------------正常--------"+mapRequest.toString()+url);
            return newUlr;
        }else{
//            System.out.println("隐藏"+url+"&mm_16510629_18916799_68766966");

            return "-1";
        }
    }

    public static String repcUrl2(String url) throws Exception{
        if(url.indexOf("activityId")!=-1){
            Map<String, String> mapRequest = CRequest.URLRequest(url);
//            System.out.println("隐藏"+mapRequest.get("activityid"));
            return "&activityId="+mapRequest.get("activityid");
        }else{
            return "-1";
        }
    }



    public static String getTime(){
        Date day=new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        return df.format(day);
    }

}
